<?php
/**

 */
define('IN_DOUCO', true);

// 强制在移动端中显示PC版
if (isset($_REQUEST['mobile'])) {
   setcookie('client', 'pc');
   if ($_COOKIE['client'] != 'pc') $_COOKIE['client'] = 'pc';
}

require (dirname(__FILE__) . '/include/init.php');

if ($_REQUEST['lang']) {
    $lang = $_REQUEST['lang'];
}else{
    $lang = 'zh';
}

require (dirname(__FILE__) . '/common.php');

$smarty->assign('dangqun_url', get_dangqun($lang));
$smarty->assign('zhaosheng_url', get_zhaosheng($lang));

if ($_REQUEST['keyword']){
    $keyword = $_REQUEST['keyword'];
}else{
    $keyword = '';
}

$where = ' WHERE lang=\'' . $lang . '\' and (title LIKE \'%' . $keyword . '%\' or content LIKE \'%' . $keyword . '%\')';

// 获取分页信息
$page = $check->is_number($_REQUEST['page']) ? trim($_REQUEST['page']) : 1;
list($limit,$article_num,$sqlexp) = $dou->pager2('article', ($_DISPLAY['article'] ? $_DISPLAY['article'] : 10), $page, $dou->rewrite_url('article_category', $cat_id), $where);

/* 获取文章列表 */
$sql = "SELECT id, title, content, image, cat_id, add_time, click, description, file1, url FROM " . $dou->table('article') . $where . " ORDER BY cat_id ASC, sort ASC, title" . $limit;
$query = $dou->query($sql);

while ($row = $dou->fetch_array($query)) {
    $url = 'info.php?id='.$row['id'];

    $add_time = date("Y-m-d", $row['add_time']);
    $add_time_short = date("m-d", $row['add_time']);
    $image = $row['image'] ? ROOT_URL . $row['image'] : '';
    
    // 如果描述不存在则自动从详细介绍中截取
    $description = $row['description'] ? $row['description'] : $dou->dou_substr($row['content'], 200, false);
    
    $article_list[] = array (
            "id" => $row['id'],
            "cat_id" => $row['cat_id'],
            "lang" => $lang,
            "title" => $row['title'],
            "image" => $image,
            "add_time" => $add_time,
            "add_time_short" => $add_time_short,
            "click" => $row['click'],
            "description" => $description,
            "file1" => $row['file1'],
            "link" => $row['url'],
            "url" => $url
    );
}


$smarty->assign('article_list', $article_list);
$smarty->assign('article_num', $article_num);
$smarty->assign('lang', $lang);


// 赋值给模板-数据

$smarty->display('search_result.dwt');

?>
